use std::collections::HashMap;

use crate::{engine::ISystem, tag, transform};

pub struct Component {}

impl Component {
    pub fn update(&mut self, transform: &transform::Component, tag: &tag::Component) {
        println!("{}:\n{:?}", tag.tag, transform.combined_matrix())
    }
}

pub struct System {
    components: HashMap<usize, Component>,
}

impl System {
    pub fn new() -> Self {
        Self {
            components: HashMap::new(),
        }
    }

    pub fn update(&mut self, tags: &tag::System, transforms: &transform::System) {
        for (entity_id, component) in &mut self.components {
            if let Some(tag) = tags.component(*entity_id) {
                if let Some(transform) = transforms.component(*entity_id) {
                    component.update(transform, tag);
                }
            }
        }
    }
}

impl ISystem<Component> for System {
    fn components(&self) -> &HashMap<usize, Component> {
        &self.components
    }

    fn components_mut(&mut self) -> &mut HashMap<usize, Component> {
        &mut self.components
    }
}
